<?php
/**
 * Created by PhpStorm.
 * User: Llj_life
 * Date: 2018/2/2
 * Time: 14:53
 */
namespace app\admin;
use app\admin\db\MysqliHelp;
    //引用php文件
    require_once 'db\MysqliHelp.php';
    require_once '../../conf/config.php';
    //链接数据库
    $mysqlihelp =  new MysqliHelp();

    //接受传递过来的参数
    $keyw = $_GET['keyword'];

    //判断传递的关键字是否为空
    if($keyw == '') {
        //关键字为空，返回搜索页面
        header("Location:../index/search.html");
        exit();
    }
    $keyw=trim($keyw);
    $keyw=$mysqlihelp->escape($keyw);
    $sql="select att.attachMethodName tcmPrescription,tcm.form,tcm.indications solution from tcmprescription tcm,attachmethod att where tcm.form like '%{$keyw}%' and tcm.id = att.tcmPrescription_id";
    $res =$mysqlihelp->search_sql($sql);
    //处理数据
    if(empty($res)) {
        echo "查无此内容，请换个关键词进行搜索！";
        exit();
    } else {
        while($result = $res->fetch_assoc()){
            echo $result['tcmPrescription'] . "<br/>";
            echo $result['form'] . "<br/>";
            echo $result['solution']."---<br/>";
            //把数据转成json格式
            $json[] = json_encode($result,256);
        }
        //生成js文件
        //file_put_contents('test.json', $json);
        return $json;
        //把没用的数据释放掉

    }




?>